package com.engine.devcom.mode.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.devcom.mode.service.SubWfRestService;
import com.engine.devcom.mode.service.impl.SubWfRestServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : hmy
 * @since : 2025/6/6
 */
public class SubWfRestAction {
    public static Logger LOG = LoggerFactory.getLogger("integration");

    private SubWfRestService getService(User user) {
        return ServiceUtil.getService(SubWfRestServiceImpl.class, user);
    }

    @POST
    @Path("/updateWfFieldValue")
    public String updateWfFieldValue(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        // 获取登录的user
        User user = HrmUserVarify.getUser(request, response);
        Map<String, Object> result = new HashMap<>();
        try {
            result.put("code", 0);
            result.putAll(getService(user).modifyFieldValue(ParamUtil.request2Map(request), user));
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            result.put("code", -1);
            result.put("msg", e.getMessage());
        }
        return JSONObject.toJSONString(result);
    }
}
